<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@3.3.7/dist/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u"
        crossorigin="anonymous">
    <title>后台管理系统</title>
    <style>
        .nav {
            width: 180px;
            background: #888;
            position: absolute;
            height: 100%;
            left: 0px;
            top: 0px;
        }

        .nav h3 {
            text-align: center;
            background: #666;
            padding: 10px;
        }

        .nav a {
            text-align: center;
            color: #fff;
            display: block;
            text-decoration: none;
            background: #333;
            padding: 5px 0;
        }

        .content {
            margin-left: 180px;
        }



        .topnav {
            height: 40px;
            line-height: 40px;
            border-bottom: 1px solid #ccc;
            position: relative;
        }

        #logout {
            position: absolute;
            right: 20px;
        }

        #mzsm{
            text-align: center;
            position: absolute;
            bottom: 20px;
            left: 50%;
            transform: translateX(-50%);
        }
    </style>
</head>

<body>
    <div>
        <div class="container-fluid">
            <div class="nav">
                <h3>管理系统</h3>
                <a href="javascript:;">商户管理</a>
            </div>
            <div class="content">
                <div class="topnav">
                    <span>后台管理</span>
                    <a href="javascript:;" id="logout">
                        退出
                    </a>
                </div>
                <main>
                    <table class="table table-hover">
                        <thead>
                            <tr>
                                <th>
                                    编号
                                </th>
                                <th>
                                    PID
                                </th>
                                <th>
                                    MD5
                                </th>
                                <th>
                                    状态
                                </th>
                                <th>
                                    操作
                                </th>
                                <th>
                                    备注
                                </th>
                            </tr>
                        </thead>
                        <tbody>
                            <!-- <tr>
                                <td>1</td>
                                <td>2088431175245912</td>
                                <td>6gxvh5q0446g607bwd1knpjb3cq2hfth</td>
                                <td>正常</td>
                                <td>
                                    <button type="button" class="btn btn-xs btn-info">启用</button>
                                    <button type="button" class="btn btn-xs btn-warning">停用</button>
                                    <button type="button" class="btn btn-xs btn-danger">修改</button>
                                </td>
                                <td>网站: p.tn18.vip</td>
                            </tr> -->
                        </tbody>

                    </table>
                </main>
            </div>
        </div>
    </div>

    <a href="mzsm.html" id="mzsm">免责声明</a>

    <script src="https://cdn.bootcss.com/jquery/3.3.1/jquery.min.js"></script>
    <script src="../assets/template/template-web.js"></script>
    <script type="text/template" id="t">
        {{each list value}}
        <tr>
            <td class='id'>{{value.id}}</td>
            <td>{{value.pid}}</td>
            <td>{{value.md5}}</td>
            {{if value.is_true==1}}
            <td>正常</td>
            {{else}}
            <td>停用</td>
            {{/if}}
            <td>
                <button type="button" dataid={{value.id}} id="start" class="btn btn-xs btn-info">启用</button>
                <button type="button" dataid={{value.id}} id="end" class="btn btn-xs btn-warning">停用</button>
                <a href="./updateshop.html?id={{value.id}}" type="button" dataid={{value.id}} id="update" class="btn btn-xs btn-danger">修改</a>
            </td>
            <td>{{value.info}}</td>
        </tr>
        {{/each}}
    </script>
    <script>
        $.ajax({
            url: './shoplist.php',
            dataType: 'json',
            success: function (msg) {

                if (msg.code == 400) {
                    location.href = './login.html'
                }

                console.log(msg)
                var json = {
                    list: msg
                }
                console.log(json)
                var str = template('t', json)
                // console.log(str)
                $('tbody').html(str)
            }
        })

        // 启用
        $('tbody').on('click', '#start', function () {
            // alert()\var 

            var id = $(this).attr('dataid')
            // console.log(id)
            $.ajax({
                url: './shopstart.php',
                data: {
                    id: id
                },
                type: 'post',
                success: function (msg) {
                    // console.log(msg)
                    if (msg == 1) {
                        alert('商户已启用')
                        location.reload()
                    } else {
                        alert('操作失败')
                        location.reload()
                    }
                }

            })

        })

        // 禁用
        $('tbody').on('click', '#end', function () {
            // alert(1)

            var id = $(this).attr('dataid')
            console.log(id)
            $.ajax({
                url: './shopend.php',
                data: {
                    id: id
                },
                type: 'post',
                success: function (msg) {
                    // console.log(msg)
                    if (msg == 1) {
                        alert('商户已停用')
                        location.reload()
                    } else {
                        alert('操作失败')
                        location.reload()
                    }
                }
            })
        })

        // 退出
        $('#logout').click(function () {
            if (confirm('确定退出?')) {
                $.ajax({
                    url: './logout.php',
                    success: function (msg) {
                        if (msg == 1) {
                            location.href = './login.html'
                        }
                    }
                })
            }
        })
    </script>
</body>

</html>